package manager

import ext.log
import mvc.model.Status
import mvc.model.TempValue
import org.json.JSONObject

object TempValueManager : Runnable {
    override fun run() {
        try {
            val result = NetworkManager.refreshTempValue()
            log("---$result", "温度报警")
            val value = TempValue.withJson(JSONObject(result))
            Status.setFridgeTemp(value)
        } catch (e: Exception) {
            e.printStackTrace()
            AsyncTask.postDelayed(this, 60 * 1000)
        }
    }

    fun refreshAsync() {
        AsyncTask.post(this)
    }
}